package fr.umlv.galcon.item;

import java.util.ArrayList;
import java.util.List;

import fr.umlv.galcon.planet.Planet;
import fr.umlv.galcon.ship.ShipAbstract;

/**
 * Singleton to manage each list of Items.<
 * 
 */
public class ItemListSingleton {
    private static ItemListSingleton instance = new ItemListSingleton();
    private final List<GraphicItem> itemList;
    private final List<Planet> planetList;
    private final List<ShipAbstract> shipList;
    private final List<Planet> clickedPlanet;

    /**
     * Constructor
     */
    private ItemListSingleton() {
	this.itemList = new ArrayList<>();
	this.planetList = new ArrayList<>();
	this.shipList = new ArrayList<>();
	this.clickedPlanet = new ArrayList<>();
    }

    /**
     * Add a PlanetAbstract into the list of clicked Planet.
     * 
     * @param p
     *            PlanetAbstract to Add.
     */
    public void addClickedPlanet(Planet p) {
	this.clickedPlanet.add(p);
    }

    /**
     * Add an Item object in the main Item list.
     * 
     * @param i
     *            Item object to Add.
     */
    public void addItem(GraphicItem i) {
	this.itemList.add(i);
    }

    /**
     * Add a PlanetAbstract into the Item list & Planet list
     * 
     * @param p
     *            PlanetAbstract to Add.
     */
    public void addPlanet(Planet p) {
	this.itemList.add(p);
	this.planetList.add(p);
    }

    /**
     * Add a ShipAbstractinto the Item list.
     * 
     * @param s
     *            ShipAbstract to Add.
     */
    public void addShip(ShipAbstract s) {
	this.itemList.add(s);
	this.shipList.add(s);
    }

    /**
     * Clear all Item list.
     */
    public void clearAll() {
	this.itemList.clear();
	this.planetList.clear();
	this.clickedPlanet.clear();
	this.shipList.clear();
    }

    /**
     * Ge the Clicked list Planet
     * 
     * @return clickedPlanet list
     */
    public List<Planet> getClickedPlanetList() {
	return this.clickedPlanet;
    }

    /**
     * Returns an instance of ItemListSingleton
     * 
     * @return ItemListSingleton Instance
     */
    public static ItemListSingleton getInstance() {
	synchronized (ItemListSingleton.class) {
	    if (instance == null)
		instance = new ItemListSingleton();
	}
	return instance;
    }

    /**
     * Get the Item list
     * 
     * @return itemList
     */
    public List<GraphicItem> getItemList() {
	return this.itemList;
    }

    /**
     * Get the Planet list
     * 
     * @return The PlanetAbstract list.
     */
    public List<Planet> getPlanetList() {
	return this.planetList;
    }

    /**
     * Get the ShipAbstract list
     * 
     * @return The ShipAbstract list.
     */
    public List<ShipAbstract> getShipList() {
	return this.shipList;
    }

    /**
     * Remove a PlanetAbstract from the clicked list planet.
     * 
     * @param p
     *            PlanetAbstract to remove.
     */
    public void removeClickedPlanet(Planet p) {
	this.clickedPlanet.remove(p);
    }
}
